﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using Cricket.LinqModel;
using Cricket.LinqData;
using System.Web.Script.Services;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

public partial class LedgerReport : System.Web.UI.Page
{
    IDataRepository _dataObject = new DataRepository();
    MatchSchedule matchSchedule;
    int Commisssion = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            HttpCookie cookie = Request.Cookies["Client"];
            if (cookie == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                bindMatch();

            }
        }
    }

    private void bindMatch()
    {
        matchSchedule = new MatchSchedule(_dataObject);
        List<GetMatchesForReportResult> lstResult = new List<GetMatchesForReportResult>();
        lstResult = matchSchedule.GetMatchesForReport();
        if (lstResult.Count > 0)
        {
            drpMatch.DataSource = lstResult;
            drpMatch.DataTextField = "Teams";
            drpMatch.DataValueField = "Id";
            drpMatch.DataBind();
            drpMatch.Items.Insert(0, new ListItem("Select Match", "0"));
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["Client"];
        if (cookie == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            CustomerBetting cust1 = new CustomerBetting(_dataObject);
            List<ClientMatchLedgerResult> lst1 = new List<ClientMatchLedgerResult>();
            lst1 = cust1.ClientMatchLedger(Convert.ToInt32(cookie["AdminId"]), Convert.ToInt32(drpMatch.SelectedValue), Convert.ToInt32(cookie["ClientId"]));
            if (lst1.Count > 0)
            {
                if (lst1[0].MatchTotal == null)
                {
                    lblMatch.Text = "0";
                }
                else
                {
                    lblMatch.Text = Convert.ToString(lst1[0].MatchTotal);
                }
            }
            else
            {
                lblMatch.Text = "0";
            }
            CustomerBetting cust2 = new CustomerBetting(_dataObject);
            List<ClientSessionLedgerResult> lst2 = new List<ClientSessionLedgerResult>();
            lst2 = cust1.ClientSessionLedger(Convert.ToInt32(cookie["AdminId"]), Convert.ToInt32(drpMatch.SelectedValue), Convert.ToInt32(cookie["ClientId"]));
            if (lst2.Count > 0)
            {
                if (lst2[0].SessionTotal == null)
                {
                    lblSession.Text = "0";
                }
                else
                {
                    lblSession.Text = Convert.ToString(lst2[0].SessionTotal);
                }
            }
            else
            {
                lblSession.Text = "0";
            }

            CustomerBetting cust3 = new CustomerBetting(_dataObject);
            List<ClientCommissionLedgerResult> lst3 = new List<ClientCommissionLedgerResult>();
            lst3 = cust3.ClientCommissionLedger(Convert.ToInt32(drpMatch.SelectedValue), Convert.ToInt32(cookie["ClientId"]));
            if (lst3.Count > 0)
            {
                if (lst3[0].CommissionTotal == null)
                {
                    lblCommission.Text = "0";
                }
                else
                {
                    lblCommission.Text = Convert.ToString(lst3[0].CommissionTotal);
                }
            }
            lblTotal.Text = Convert.ToString(Convert.ToDecimal(lblMatch.Text) + Convert.ToDecimal(lblSession.Text) + Convert.ToDecimal(lblCommission.Text));

        }
    }

}